package com.inews.util;

import weibo4android.Weibo;
import weibo4android.WeiboException;
import weibo4android.http.AccessToken;
import weibo4android.http.RequestToken;

public class AuthUtil {

	private static Weibo weibo;
	private static RequestToken requestToken;

	static {
		System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
		System.setProperty("weibo4j.oauth.consumerSecret",
				Weibo.CONSUMER_SECRET);
		weibo = new Weibo();
	}

	/**
	 * 获取认证的URL.
	 * 
	 * @return the authorization url
	 */
	public static String getAuthorizationURL() {
		String authorizationURL = null;
		try {
			requestToken = weibo.getOAuthRequestToken();
			authorizationURL = requestToken.getAuthorizationURL();
		} catch (WeiboException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return authorizationURL;
	}

	/**
	 * 获取AccessToken信息
	 * 
	 * @param pin
	 * @return
	 */
	public static AccessToken getAccessToken(String pin) {
		try {
			AccessToken accessToken = requestToken.getAccessToken(pin);
			return accessToken;
		} catch (WeiboException e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
